﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    using DAL.Entities;

    public class DichvuclsDAL : BaseDAL, UTL.IBaseDAL 
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT *,b.TENLOAIDICHVU FROM dichvu_cls a join LOAIDICHVU b on a.maloaidichvu=b.maloaidichvu";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            string sql = @"DELETE FROM dichvu_cls WHERE madichvu = '{0}'";
            sql = string.Format(sql,id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (dichvucls)obj;
            string sql = @"INSERT INTO dichvu_cls(madichvu,tendichvu,maloaidichvu) VALUES('{0}',N'{1}','{2}')";
            sql = string.Format(sql,o.madichvu,o.tendichvu,o.maloaidichvu);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (dichvucls)obj;
            string sql = @"UPDATE dichvu_cls SET tendichvu=N'{0}', maloaidichvu='{1}' where madichvu='{2}'";
            sql = string.Format(sql,o.tendichvu,o.maloaidichvu,o.madichvu);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        public DataTable Select_loaidichvu()
        {
            string sql = @" SELECT maloaidichvu as id, tenloaidichvu as ten FROM loaidichvu";
            return ExecuteQuery(sql);
        }
        public string Select_max()
        {
            string sql = @"SELECT max(substring(MADICHVU,3,LEN(MADICHVU)-2)) as id FROM DICHVU_CLS";
            DataTable dt = ExecuteQuery(sql);
            return dt.Rows.Count > 0 ? dt.Rows[0]["id"] + "" : "0";

        }


        public bool deleteobj(object obj)
        {
            throw new NotImplementedException();
        }
    }
}
